package client;

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.Serializable;

import javax.swing.*;

public class NonInPartita extends JFrame implements ActionListener,Serializable {
	
	public JButton crea;
	public JButton accedi;
	public JButton lista;
	public JButton classifica;
	public JButton logout;
	
	private int risp ;
	
	public NonInPartita(){
		super("Schermata non in partita");
		setExtendedState(MAXIMIZED_BOTH);
		setDefaultCloseOperation(EXIT_ON_CLOSE);
		setLayout(new BorderLayout());
		GridBagConstraints c = new GridBagConstraints();
		c.fill = GridBagConstraints.CENTER;
		crea = new JButton("Crea razza dino");
		accedi = new JButton("Accedi alla partita");
		lista = new JButton("Lista giocatori");
		classifica = new JButton("Classifica");
		logout = new JButton("Logout");
		
		crea.addActionListener(this);
		accedi.addActionListener(this);
		lista.addActionListener(this);
		classifica.addActionListener(this);
		logout.addActionListener(this);
		
		JPanel pannello1 = new JPanel();
		pannello1.setLayout(new FlowLayout());
		
		pannello1.add(crea);
		pannello1.add(accedi);
		pannello1.add(lista);
		pannello1.add(classifica);
		pannello1.add(logout);
		
		pannello1.setOpaque(false);	
		
		PannelloSfondo pannello = new PannelloSfondo(new File("sfondo2.jpg"));
		pannello.setLayout(new GridBagLayout());
		
		pannello.add(pannello1, c);
		
		add(pannello, BorderLayout.CENTER);
		
		setVisible(true);
		
		synchronized(this){
			try {
				wait();
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
		
		
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		synchronized(this){
			if(e.getSource().equals(crea)){
				risp=1;
				notifyAll();
				dispose();
			}
		}
		synchronized(this){
			if(e.getSource().equals(accedi)){
				risp=2;
				notifyAll();
				dispose();
			}
		}
		synchronized(this){
			if(e.getSource().equals(lista)){
				risp=3;
				notifyAll();
				dispose();
			}
		}
		synchronized(this){
			if(e.getSource().equals(classifica)){
				risp=4;
				notifyAll();
				dispose();
			}
		}
		synchronized(this){
			if(e.getSource().equals(logout)){
				risp=5;
				notifyAll();
				dispose();
			}
		}
		
	}
	
	public int getRisp(){
		return risp;
	}
	

}
